class Solution {
public:
    int subarraysDivByK(vector<int>& nums, int k)
    {
        unordered_map<int, int> hash;
        hash[0] = 1;
        int sum = 0, ret = 0, t = 0;
        for (auto& x : nums)
        {
            sum += x;
            t = (sum % k + k) % k;
            if (hash[t])ret += hash[t];
            hash[t]++;
        }

        return ret;

    }
};